﻿using System;
using System.Collections.Generic;
using System.Text;
namespace Test {
	class LingWords {
		static void MainX() {
			Cache cac=new Cache("lin");
			MAL dal=new MAL();
			dal.NonQry("drop table dictWrd");
			dal.NonQry("create table dictWrd(id int auto_increment primary key,word varchar(500)character set utf8,src varchar(500),link varchar(500),status char,lastchecked datetime)character set utf8 collate utf8_polish_ci");
			string[] langs="polsko-angielski,angielsko-polski".Split(',');
			foreach(string lang in langs)
			{
				string link0="http://ling.pl/slownik/"+lang+"/";
				string page0=cac.Get(link0,500);

				string lettersList=Nod.Dbl(page0,"<ul class=\"wordListUl\">");

				string[] letters=Nod.Rxs(lettersList,"<a.+?>(.+?)</a>");
				foreach(string letter in letters)
				{
					string link1=link0+"slowa/"+letter.ToLower()+"/";
					string page1=cac.Get(link1,500);

					string maxPageNum0=Nod.Find(page1,"Ostatnia &rsaquo;");
					string maxPageNum1="1";
					if(maxPageNum0!="")
						maxPageNum1=Nod.Rx(maxPageNum0,"href=\".+?/(\\d+?)\"");
					for(int i=1;i<=int.Parse(maxPageNum1);i++)
					{
						string link2=link1+i;
						string page2=cac.Get(link2,500);

						string[] words=Nod.Dbls(page2,"<div class=\"grid_4 alpha omega\">");


						foreach(string wordDiv in words)
						{


							string word=Nod.InnerText(wordDiv).Replace("\\","");
							string link=Nod.Rx(wordDiv,"href=\"(.+?)\"");

							dal.NonQry("insert into dictWrd(word,src,link)values('{0}','{1}','{2}')",word,link2,link);

						}




					}
				}
			}



		}
	}
}
